<%@page import="tianqi.entity.UserY"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>田奇-晒单模块</title>
		<meta charset="utf-8">
		<link rel="stylesheet" type="text/css" href="css/myPerson.css">
    	<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
    	<script type="text/javascript" charset="utf-8" src="js/jquery-1.11.3.js"></script>
    	<script type="text/javascript" charset="utf-8" src="js/jquery.form.js"></script>
    	<script type="text/javascript" charset="utf-8" src="js/bootstrap.min.js"></script>
	</head>
<body>
	    <div id="header" class="clear">
    <div class="mark1 lf clear">
        <img id="touxiang" width="90" height="90" style="border-radius:50%;border-color: #e4393c;" src="${user.txImg==null?'upload/mr.png':user.txImg }"></img>
    </div>

    <p class="lf clear" style="margin-top: 15px;"><a href="#" style="color:#fff;">尊敬的: <span id="uname">${user.uname } </span>,您好！欢迎来到个人中心页面。</a></p>

    </div>
    <div id="section" class="clear">
        <form id="form1" class="form-horizontal" action="">

            <a href="javascript:;" class="file clear">选择头像
                <input type="file" onchange="tx();" name="imgsFile"/>
            </a>

            <div class="form-group">
                <label for="inputEmail3" class="col-sm-2 control-label">昵称:</label>
                <div class="col-sm-10">
                    <input id="uname1" type="text" class="form-control" placeholder="${user.uname }" value="${user.uname }">
                	<input id="uid" type="hidden"  value="${user.uid }">
                </div>
            </div>
            <div class="form-group">
                <label for="inputEmail3" class="col-sm-2 control-label">手机/邮箱:</label>
                <div class="col-sm-10">
                    <input id="zname" type="text" class="form-control" id="inputEmail3" placeholder="${user.zname }" value="${user.zname }">
                </div>
            </div>
            <div class="form-group">
                <label for="inputEmail3" class="col-sm-2 control-label">账户余额:</label>
                <div class="col-sm-10">
                    <input id="mon" type="text" readonly class="form-control" id="inputEmail3" placeholder="${user.money }" >
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <a class="btn btn-success" href="javascript:tj();">提交</a>
                    <a class="btn btn-success" href="${pageContext.request.contextPath}/youge.tq">取消</a>
                </div>
            </div>
        </form>



    </div>
	
    <script>
	//将 头像信息入库
	function saveTX(res){
		 $.ajax({
			    type:"post",
			    url:"${pageContext.request.contextPath}/saveTX.tq",
			    data:{txImg:res,uid:"${user.uid }"},
			    success:function(res){
			      console.log(res);
			      if(res == "true"){
			    	  alert("头像上传成功！");
			      }else{
			    	  alert("头像上传失败");
			      }
			    },
			    error:function(res){
			      alert(res);
			    }
			  })
	}
	
	
        
        //上传头像 图片
        function tx(){
        	alert("上传头像");
        	var option = {
        			url:"${pageContext.request.contextPath}/uplodeImg.tq",//一旦指定了url那么表单中的action的url就被覆盖了，如果不指定url就用表单的原有的url
        			dataType:"text",
        			data:{
        				fileName:"imgsFile"
        			},
        			success:function(responseText){
        				//把json格式的字符串解析成json对象
        				var jsonObj = $.parseJSON(responseText);
        				if(jsonObj.relativePath == "error"){
        					alert("请选择文件");
        					return;
        				}
        				//$(".mark").html('<img id="touxiang" width="90" height="90" style="border-radius:50%;" title="头像" src="'+jsonObj.relativePath+'?d='+new Date()+'">');
        				saveTX(jsonObj.relativePath);
        				//$(".mark").css("background-image","url("+jsonObj.relativePath+")")
        				$("#touxiang").attr('src',jsonObj.relativePath+"?d="+new Date());
        				alert($("#touxiang").attr('src'));
        				
        			},
        			error:function(){
        				alert("系统错误");
        			}
        	};
        	$("#form1").ajaxSubmit(option);
        }
        
        
        //用户  提交个人信息
        function tj(){
        	  $.ajax({
				    type:"post",
				    url:"${pageContext.request.contextPath}/toMyPerson.tq",
				    data:{
				    	uname:$("#uname1").val(),
				    	zname:$("#zname").val(),
				    	uid:$("#uid").val()
				    },
				    success:function(res){
				      console.log(res);
				      if(res == "1"){
				    	  alert("恭喜您  修改成功！ 3秒后跳转至首页！");
				    	  setTimeout(function(){location.href="${pageContext.request.contextPath}/youge.tq"},2500);
				    	  
				      }else{
				    	  alert("修改失败");
				      }
				    },
				    error:function(res){
				      alert(res);
				    }
				  })
        }

    </script>

</body>
</html>